package com.jqr.activity.listviewdemo.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.jqr.activity.listviewdemo.R;

import java.util.ArrayList;
import java.util.List;

public class ArrayListActivity extends AppCompatActivity {
    private ListView listView;
    private List<String> stringList;


    private ArrayAdapter<String> arrayAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_array_list);
        listView=findViewById(R.id.arrayListView);


        stringList=new  ArrayList<>();

        for (int i=0 ;i<50;i++){
            stringList.add("list_view_"+i);
        }

        arrayAdapter=new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,stringList);


        listView.setAdapter(arrayAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ArrayListActivity.this,stringList.get(position),Toast.LENGTH_LONG).show();
            }
        });

    }
}